package com.sumainfor.pc.gmio.service.impl;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.gmio.dao.DiWithdrawalExtMapper;
import com.sumainfor.pc.gmio.feign.Zfeign.ZpcMktFeign;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 退租
 * <p>
 *
 * @author: zc
 * @create: 2019-09-21 19:56
 **/
@Service
public class DiWithdrawalExtService implements Serializable {

    @Autowired
    DiWithdrawalExtMapper diWithdrawalExtMapper;

    @Autowired
    ZpcMktFeign zpcMktFeign;


    /**
     * 根据合同编号获取详情
     * @author zhoucong
     * @data 2019/9/21
     * @Param
     * @return
     */
    public JsonResult getWithdrawalExt(String PaId) {
        JsonResult resultOne = new JsonResult();
        Map<String, Object> params = new HashMap<>();
        params.put("zczsStatus",1);
        List<Map<String, Object>> getCommunityList = diWithdrawalExtMapper.getWithdrawalExt(PaId);
        List<String> idList = new ArrayList<String>();
        List<String> tList = new ArrayList<String>();
        for (Map<String, Object> map : getCommunityList) {
            if (map.get("HouInfoId") != null) {
                idList.add(map.get("HouInfoId").toString());
            }
            if (map.get("TenId") != null) {
                tList.add(map.get("TenId").toString());
            }
        }
        params.put("idList", idList);//房源编号
        params.put("TenantList", tList);//租客编号
        JsonResult result = zpcMktFeign.getHouInfoListForDbill(params);
        System.out.println("市场部返回的数据:" + result);
        if (result.get("errorCode").equals("0")) {
            Map<String, Object> maktMap = (Map<String, Object>) result.get("result");
            List<Map<String, Object>> mktList = (List<Map<String, Object>>) maktMap.get("list");
            List<Map<String, Object>> tenList = (List<Map<String, Object>>) maktMap.get("tList");
            System.out.println("tenList:" + tenList);
            int count = 0;
            for (Map<String, Object> map : mktList) {
                for (Map<String, Object> map2 : getCommunityList) {
                    if (MapUtils.getString(map, "HouInfoId").equals(MapUtils.getString(map2, "HouInfoId"))) {
                        map2.putAll(map);
                    }
                }
            }
            for (Map<String, Object> map : tenList) {
                for (Map<String, Object> map2 : getCommunityList) {
                    if (MapUtils.getString(map, "TenId").equals(MapUtils.getString(map2, "TenId"))) {
                        map2.putAll(map);
                    }
                }
            }


        }
        return resultOne.put(getCommunityList);
    }
}
